#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace NativeTest_Question36
{

	class MyStack
	{
	public:
		MyStack();
		~MyStack();
		bool empty();
		int top();
		int size();
		void push(int val);
		void pop();
	private:
		int* data;
		int index;
	};

	MyStack::MyStack()
	{
		data = new int[10];
		index = -1;
	}

	MyStack::~MyStack()
	{
		//delete[] data;
	}
	bool MyStack::empty()
	{
		return index == -1;
	}
	int MyStack::top()
	{
		if(!empty())
			return this->data[index];
		else
			return INT_MIN;
	}
	int MyStack::size()
	{
		return index + 1;
	}
	void MyStack::push(int val)
	{
		this->data[++index] =val;
	}
	void MyStack::pop()
	{
		if(!empty())
			index--;
	}
	
	void Sort(MyStack& s, MyStack& r)
	{
		while(!s.empty())
		{
			int top = s.top();
			s.pop();
			while (!r.empty() && top > r.top())
			{
				s.push(r.top());
				r.pop();
			}

			r.push(top);
		}
	}
}
namespace NativeTest
{
	using namespace NativeTest_Question36;
	TEST_CLASS(Question36)
	{
	public:
		
		TEST_METHOD(Question36_TestMethod1)
		{
			// TODO: Your test code here
			MyStack s;
			s.push(1);s.push(2);s.push(4);s.push(3);s.push(5);s.push(3);s.push(1);
			int size = s.size();
			MyStack r ;
			Sort(s,r);

			Assert::AreEqual(size, r.size());
			Assert::AreEqual(1, r.top());
			r.pop();  Assert::AreEqual(1, r.top());
			r.pop();  Assert::AreEqual(2, r.top());
			r.pop();  Assert::AreEqual(3, r.top());
			r.pop();  Assert::AreEqual(3, r.top());
			r.pop();  Assert::AreEqual(4, r.top());
			r.pop();  Assert::AreEqual(5, r.top());
		}

	};
}